import * as Sequelize from "sequelize";
import { Application } from "egg";

interface DicAttributes {
    id: string;
    table_name: string;
    col_name: string;
    key: string;
    value: string;
    create_user_id: string;
    modify_user_id: string;
    create_time: string;
    modify_time: string;
}

type DicInstance = Sequelize.Instance<DicAttributes> & DicAttributes;

export default (app: Application) => {
    const { STRING, CHAR, UUID, UUIDV4, DATE,NOW } = app.Sequelize;
    const attributes:SequelizeAttributes<DicAttributes> = {
        id: { type: UUID, primaryKey: true, allowNull: false, defaultValue: UUIDV4 },
        table_name: { type: STRING(50), allowNull: false },
        col_name: { type: STRING(50), allowNull: false },
        key: { type: STRING(50), allowNull: false },
        value: { type: STRING(50), allowNull: false },
        create_user_id: { type: UUID, allowNull: false },
        modify_user_id: { type: UUID, allowNull: false },
        create_time: { type: DATE, allowNull: false ,defaultValue: NOW},
        modify_time: { type: DATE, allowNull: false ,defaultValue: NOW}
    };
    const model = app.model.define<DicInstance, DicAttributes>("Dic", attributes, {
        tableName: 't_dic'
    });
    return model
};
/*

(sequalize: Sequelize.Sequelize) => {
    console.log(sequalize)
    const attributes: SequelizeAttributes<AppAttributes> = {
        org_id: { type: Sequelize.UUID, primaryKey: true, allowNull: false },
        app_id: { type: Sequelize.UUID, primaryKey: true, allowNull: false, defaultValue: Sequelize.UUIDV4 },
        app_name: { type: Sequelize.STRING(50), allowNull: false },
        status: { type: Sequelize.CHAR(3), allowNull: false, defaultValue: "0" },
        description: { type: Sequelize.STRING(200), allowNull: false },
        create_user_id: { type: Sequelize.UUID, allowNull: false },
        boe_insertTime: { type: Sequelize.DATE, allowNull: false },
        boe_updateTime: { type: Sequelize.DATE, allowNull: false }
    };
    const model = sequalize.define<AppInstance, AppAttributes>("App", attributes);
    model.associate = (models)=>{
        model.belongsTo(models.Org,{foreignKey:"app_id"})
        model.hasMany(models.Version,{foreignKey:"app_id"})
    }
    return model
};*/
